import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Ellipse2D.Double;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Bank;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Environment;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.GrandExchange;
import org.rsbot.script.methods.GrandExchange.GEItem;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.methods.Inventory;
import org.rsbot.script.methods.Keyboard;
import org.rsbot.script.methods.Magic;
import org.rsbot.script.methods.Menu;
import org.rsbot.script.methods.Mouse;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Players;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

@ScriptManifest(authors={"Fallen"}, keywords={"Magic"}, name="Fallen's Superheater", version=5.99D, description="Superheats any kind of bars.")
public class FallenSuperheater extends Script
  implements PaintListener, MessageListener, MouseListener, MouseMotionListener
{
  private boolean renew;
  private long startTime;
  private final long scriptStartTime = 0L;
  private long runTime;
  private long millis;
  private long seconds;
  private long minutes;
  private long hours;
  private int BarCounter;
  private int XPGained;
  private int XPGainedSmithing;
  private int XPGainedMagic;
  private int startXPM;
  private int startXPS;
  private int startLevelM;
  private int levelsGainedM;
  private int startLevelS;
  private int levelsGainedS;
  private int currentLevelM;
  private int currentLevelS;
  private Image BKG;
  private int toNextLvlS;
  private int nextLvlS;
  private int XPToLevelS;
  private int toNextLvlM;
  private int nextLvlM;
  private int XPToLevelM;
  private long timerStart;
  private long pauseTimer;
  private long tempTimer;
  private long tempTimer2;
  private boolean gathered;
  private boolean MTTNL;
  private boolean STTNL;
  private Point mouseSpot;
  private Timer expTimeOut;
  private int tempExp;
  private int browser;
  private boolean readyToCast;
  private int EXP1;
  private int EXP2;
  private Shape Circle;
  private Rectangle Rect;
  private Point P;
  private int R;
  private boolean DRAW;
  private double BarEXP;
  private String BarType;
  private static int AmountOfCasts;
  private String Status;
  private String GUIString;
  private Object GUIString2;
  private Object GUIString3;
  private Object GUIString4;
  private boolean worked;
  private Properties OPTION_FILE;
  private static int Percentage = 100;
  private static int AFK1;
  private static int AFK2;
  private static int Mouse1 = 50;
  private int Mouse2;
  private final int cBag = 18339;
  private boolean coalBag;
  private boolean filled;
  private boolean bankTwice;
  private int OpenedBank;
  private boolean Continue;
  private boolean BankTime;
  private boolean DirectHeat;
  private boolean TakeAShot;
  private boolean DoTheMath;
  private int Option;
  private final boolean smartHeat = true;
  private int BarID;
  private int Ore1;
  private int Ore2;
  private int Ore1WD;
  private int Ore2WD;
  private int Ore2PerSpell;
  private int Ore1InvAm;
  private int Ore2InvAm;
  private final int copperOre = 436;
  private final int tinOre = 438;
  private final int ironOre = 440;
  private final int silverOre = 442;
  private final int goldOre = 444;
  private final int coalOre = 453;
  private final int mithrilOre = 447;
  private final int adamantOre = 449;
  private final int runeOre = 451;
  private final int bronzeBar = 2349;
  private final int ironBar = 2351;
  private final int steelBar = 2353;
  private final int silverBar = 2355;
  private final int goldBar = 2357;
  private final int mithrilBar = 2359;
  private final int adamantBar = 2361;
  private final int runeBar = 2363;
  private final int nature = 561;
  private int BarPrice;
  private int Ore1Price;
  private int Ore2Price;
  private int naturePrice;
  private final int BOOK_KNOWLEDGE_ID = 11640;
  private final int LAMP_ID = 2528;
  private final int MYSTERY_BOX_ID = 6199;
  private final int BOX_ID = 14664;
  private final Rectangle testRec;
  public boolean WaitForStart;
  FallenSuperheater.GUI SuperheaterGUI;

  public FallenSuperheater()
  {
    this.renew = true;
    this.startTime = 0L;
    this.scriptStartTime = 0L;
    this.runTime = 0L;
    this.millis = 0L;
    this.seconds = 0L;
    this.minutes = 0L;
    this.hours = 0L;
    this.BarCounter = 0;
    this.XPGained = 0; this.XPGainedSmithing = 0; this.XPGainedMagic = 0;

    this.timerStart = 0L;
    this.pauseTimer = 0L;
    this.tempTimer = 0L;
    this.tempTimer2 = 0L;
    this.gathered = false;
    this.MTTNL = false;
    this.STTNL = false;

    this.expTimeOut = new Timer(300000L);
    this.tempExp = 0;
    this.browser = 0;
    this.readyToCast = true;

    this.DRAW = false;

    this.BarEXP = 0.0D;

    this.worked = false;

    this.Mouse2 = 8;

    this.cBag = 18339;
    this.coalBag = false; this.filled = false;
    this.bankTwice = false;
    this.OpenedBank = 0;
    this.Continue = false;
    this.BankTime = false;
    this.DirectHeat = false;
    this.TakeAShot = false;
    this.DoTheMath = false;
    this.Option = 1;
    this.smartHeat = true;

    this.BarID = 0;
    this.Ore1 = 0;
    this.Ore2 = 0;
    this.Ore1WD = 0;
    this.Ore2WD = 0;
    this.Ore2PerSpell = 0;
    this.Ore1InvAm = 0;
    this.Ore2InvAm = 0;

    this.copperOre = 436;
    this.tinOre = 438;
    this.ironOre = 440;
    this.silverOre = 442;
    this.goldOre = 444;
    this.coalOre = 453;
    this.mithrilOre = 447;
    this.adamantOre = 449;
    this.runeOre = 451;

    this.bronzeBar = 2349;
    this.ironBar = 2351;
    this.steelBar = 2353;
    this.silverBar = 2355;
    this.goldBar = 2357;
    this.mithrilBar = 2359;
    this.adamantBar = 2361;
    this.runeBar = 2363;

    this.nature = 561;

    this.BarPrice = 0;
    this.Ore1Price = 0;
    this.Ore2Price = 0;
    this.naturePrice = 0;

    this.BOOK_KNOWLEDGE_ID = 11640;
    this.LAMP_ID = 2528;
    this.MYSTERY_BOX_ID = 6199;
    this.BOX_ID = 14664;

    this.testRec = null;

    this.WaitForStart = true;
  }

  public void onRepaint(Graphics paramGraphics)
  {
    if ((!this.game.isLoggedIn()) || (isPaused()) || (!isActive())) {
      if (!this.gathered) {
        this.timerStart = System.currentTimeMillis();
        this.gathered = true;
      }
      this.tempTimer = (System.currentTimeMillis() - this.timerStart - this.tempTimer2);
    } else {
      this.tempTimer = 0L;
      this.tempTimer2 = 0L;
      this.gathered = false;
    }
    this.pauseTimer += this.tempTimer;
    this.tempTimer2 += this.tempTimer;

    this.runTime = (System.currentTimeMillis() - 0L);
    this.seconds = (this.runTime / 1000L);
    if (this.startXPM == 0) {
      this.startXPM = this.skills.getCurrentExp(6);
    }
    if (this.startXPS == 0) {
      this.startXPS = this.skills.getCurrentExp(13);
    }
    if (this.startLevelM == 0) {
      this.startLevelM = this.skills.getCurrentLevel(6);
    }
    if (this.startLevelS == 0) {
      this.startLevelS = this.skills.getCurrentLevel(13);
    }
    this.XPGainedMagic = (this.skills.getCurrentExp(6) - this.startXPM);
    int i = (int)(this.XPGainedMagic * 3600000.0D / (System.currentTimeMillis() - this.startTime - this.pauseTimer));

    this.XPGainedSmithing = (this.skills.getCurrentExp(13) - this.startXPS);
    this.BarCounter = (this.XPGainedMagic / 53);
    int j = (int)(this.XPGainedSmithing * 3600000.0D / (System.currentTimeMillis() - this.startTime - this.pauseTimer));

    int k = this.BarPrice - this.Ore1Price - this.Ore2Price - this.naturePrice;
    int m = (int)(k * this.BarCounter * 3600000.0D / (System.currentTimeMillis() - this.startTime - this.pauseTimer));

    this.levelsGainedM = (this.skills.getCurrentLevel(6) - this.startLevelM);
    this.levelsGainedS = (this.skills.getCurrentLevel(13) - this.startLevelS);
    this.currentLevelM = this.skills.getCurrentLevel(6);
    this.currentLevelS = this.skills.getCurrentLevel(13);
    this.millis = (System.currentTimeMillis() - this.startTime - this.pauseTimer);
    this.hours = (this.millis / 3600000L);
    this.millis -= this.hours * 3600000L;
    this.minutes = (this.millis / 60000L);
    this.millis -= this.minutes * 60000L;
    this.seconds = (this.millis / 1000L);

    if ((this.game.getCurrentTab() == 4) && (this.DRAW)) {
      paramGraphics.setColor(Color.GREEN);
      paramGraphics.drawRect(this.Rect.x, this.Rect.y, this.Rect.width, this.Rect.height);
      paramGraphics.setColor(Color.CYAN);

      paramGraphics.drawOval((int)(this.P.getX() - this.R / 2), (int)(this.P.getY() - this.R / 2), this.R, this.R);

      paramGraphics.setColor(Color.BLACK);
      paramGraphics.fillOval((int)(this.P.getX() - 2.0D), (int)(this.P.getY() - 2.0D), 4, 4);
    }

    Point localPoint = this.mouse.getLocation();
    paramGraphics.setColor(new Color(90, 90, 255, 180));
    paramGraphics.fillRoundRect((int)localPoint.getX() - 10, (int)localPoint.getY() - 1, 21, 3, 3, 3);

    paramGraphics.fillRoundRect((int)localPoint.getX() - 1, (int)localPoint.getY() - 10, 3, 21, 3, 3);

    if (this.testRec != null) {
      paramGraphics.setColor(Color.GREEN);
      paramGraphics.drawRect(this.testRec.x, this.testRec.y, this.testRec.width, this.testRec.height);
    }

    paramGraphics.setColor(new Color(0, 0, 200, 130));
    paramGraphics.fillRect(497, 458, 15, 14);
    paramGraphics.setColor(new Color(0, 0, 0, 255));
    paramGraphics.drawRect(497, 458, 15, 14);
    paramGraphics.setColor(new Color(255, 255, 255, 255));
    paramGraphics.drawString("" + this.Option, 502, 470);
    this.toNextLvlS = this.skills.getPercentToNextLevel(13);
    this.XPToLevelS = this.skills.getExpToNextLevel(13);
    this.nextLvlS = (this.skills.getCurrentLevel(13) + 1);
    this.toNextLvlM = this.skills.getPercentToNextLevel(6);
    this.XPToLevelM = this.skills.getExpToNextLevel(6);
    this.nextLvlM = (this.skills.getCurrentLevel(6) + 1);

    if (this.Option == 1)
    {
      paramGraphics.drawImage(this.BKG, 7, 297, null);
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.BLUE);
      paramGraphics.drawString("v5.99", 443, 424);

      if (this.Status != "Loading...") {
        paramGraphics.setFont(new Font("Verdana", 0, 13));
        paramGraphics.setColor(Color.WHITE);
        paramGraphics.drawString("" + this.hours + ":" + this.minutes + ":" + this.seconds + ".", 80, 437);
      }
      else {
        paramGraphics.setFont(new Font("Verdana", 0, 13));
        paramGraphics.setColor(Color.WHITE);
        paramGraphics.drawString("Loading...", 80, 437);
      }

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      if ((!this.game.isLoggedIn()) || (isPaused())) {
        this.Status = "Paused.";
      }
      paramGraphics.drawString("" + this.Status, 40, 459);

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(54, 359, 169, 16);
      paramGraphics.drawRect(53, 358, 170, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(54, 359, 169, 8);
      paramGraphics.setColor(new Color(90, 90, 255, 100));
      paramGraphics.fillRect(56, 361, (int)(this.toNextLvlM * 165 / 100.0D), 12);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + this.toNextLvlM + "% to " + this.nextLvlM + " Mage (" + this.XPToLevelM / 1000 + "k Xp)", 70, 371);

      paramGraphics.setColor(Color.CYAN);
      paramGraphics.drawString("XP Gained: " + this.XPGainedMagic + " (" + i / 1000 + "k Xp/h)", 53, 391);

      paramGraphics.drawString("Level: " + this.currentLevelM + " (" + this.levelsGainedM + ")", 53, 404);

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(263, 359, 169, 16);
      paramGraphics.drawRect(262, 358, 170, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(263, 359, 169, 8);
      paramGraphics.setColor(new Color(250, 150, 70, 100));
      paramGraphics.fillRect(265, 361, (int)(this.toNextLvlS * 165 / 100.0D), 12);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + this.toNextLvlS + "% to " + this.nextLvlS + " Smith (" + this.XPToLevelS / 1000 + "k Xp)", 279, 371);

      paramGraphics.drawString("XP Gained: " + this.XPGainedSmithing + " (" + j / 1000 + "k Xp/h)", 262, 391);

      paramGraphics.drawString("Level: " + this.currentLevelS + " (" + this.levelsGainedS + ")", 262, 404);

      paramGraphics.setColor(Color.YELLOW);
      if (this.DoTheMath) {
        paramGraphics.drawString("Profit: " + k * this.BarCounter + " (" + m / 1000 + "k/h)", 262, 429);

        paramGraphics.drawString("Profit/" + this.BarType + " Bar: " + k, 262, 455);
      }
      paramGraphics.drawString("Bars: " + this.BarCounter + " " + this.BarType + " Bars" + " (" + i / 53 + "/h)", 262, 442);

      if (AmountOfCasts > 0) {
        paramGraphics.setFont(new Font("Verdana", 0, 9));
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("Casts left: " + (AmountOfCasts - this.BarCounter), 390, 15);
      }

    }

    if (this.Option == 2)
    {
      paramGraphics.drawImage(this.BKG, 16, 154, null);
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.BLUE);
      paramGraphics.drawString("v5.99", 452, 281);

      if (this.Status != "Loading...") {
        paramGraphics.setFont(new Font("Verdana", 0, 13));
        paramGraphics.setColor(Color.WHITE);
        paramGraphics.drawString("" + this.hours + ":" + this.minutes + ":" + this.seconds + ".", 89, 294);
      }
      else {
        paramGraphics.setFont(new Font("Verdana", 0, 13));
        paramGraphics.setColor(Color.WHITE);
        paramGraphics.drawString("Loading...", 89, 294);
      }

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.drawString("" + this.Status, 49, 316);

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(63, 216, 169, 16);
      paramGraphics.drawRect(62, 215, 170, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(63, 216, 169, 8);
      paramGraphics.setColor(new Color(90, 90, 255, 100));
      paramGraphics.fillRect(65, 218, (int)(this.toNextLvlM * 165 / 100.0D), 12);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + this.toNextLvlM + "% to " + this.nextLvlM + " Mage (" + this.XPToLevelM / 1000 + "k Xp)", 70, 228);

      paramGraphics.setColor(Color.CYAN);
      paramGraphics.drawString("XP Gained: " + this.XPGainedMagic + " (" + i / 1000 + "k Xp/h)", 62, 248);

      paramGraphics.drawString("Level: " + this.currentLevelM + " (" + this.levelsGainedM + ")", 62, 261);

      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.fillRect(272, 216, 169, 16);
      paramGraphics.drawRect(271, 215, 170, 17);
      paramGraphics.setColor(new Color(51, 51, 51));
      paramGraphics.fillRect(272, 216, 169, 8);
      paramGraphics.setColor(new Color(250, 150, 70, 100));
      paramGraphics.fillRect(274, 218, (int)(this.toNextLvlS * 165 / 100.0D), 12);
      paramGraphics.setColor(Color.WHITE);
      paramGraphics.drawString("" + this.toNextLvlS + "% to " + this.nextLvlS + " Smith (" + this.XPToLevelS / 1000 + "k Xp)", 288, 228);

      paramGraphics.drawString("XP Gained: " + this.XPGainedSmithing + " (" + j / 1000 + "k Xp/h)", 271, 248);

      paramGraphics.drawString("Level: " + this.currentLevelS + " (" + this.levelsGainedS + ")", 271, 261);

      paramGraphics.setColor(Color.YELLOW);
      if (this.DoTheMath) {
        paramGraphics.drawString("Profit: " + k * this.BarCounter + " (" + m / 1000 + "k/h)", 271, 286);

        paramGraphics.drawString("Profit/" + this.BarType + " Bar: " + k, 271, 312);
      }
      paramGraphics.drawString("Bars: " + this.BarCounter + " " + this.BarType + " Bars" + " (" + i / 53 + "/h)", 271, 299);

      if (AmountOfCasts > 0) {
        paramGraphics.setFont(new Font("Verdana", 0, 9));
        paramGraphics.setColor(Color.RED);
        paramGraphics.drawString("Casts left: " + (AmountOfCasts - this.BarCounter), 390, 15);
      }
    }
    int n;
    int i1;
    long l3;
    long l4;
    if (this.MTTNL) {
      n = (int)this.mouseSpot.getX();
      i1 = (int)this.mouseSpot.getY();

      paramGraphics.setColor(new Color(50, 50, 255, 230));
      paramGraphics.fillRect(n, i1, 150, 25);
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.drawRect(n, i1, 150, 25);
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.WHITE);
      try {
        if (i > 0) {
          long l1 = this.XPToLevelM / (i / 3600);
          l3 = l1 / 3600L;
          l1 -= l3 * 3600L;
          l4 = l1 / 60L;
          l1 -= l4 * 60L;
          paramGraphics.drawString("Next level in: " + l3 + ":" + l4 + ":" + l1, n + 8, i1 + 11);
        }
        else {
          paramGraphics.drawString("Next level in: 0:0:0", n + 8, i1 + 11);
        }
      } catch (Exception localException1) {
        paramGraphics.drawString("Next level in: -1:-1:-1", n + 8, i1 + 11);
      }
      paramGraphics.drawString("Casts to next level: " + this.XPToLevelM / 53, n + 8, i1 + 22);
    }

    if (this.STTNL) {
      n = (int)this.mouseSpot.getX();
      i1 = (int)this.mouseSpot.getY();
      paramGraphics.setColor(new Color(210, 110, 50, 230));
      paramGraphics.fillRect(n, i1, 150, 25);
      paramGraphics.setColor(new Color(0, 0, 0));
      paramGraphics.drawRect(n, i1, 150, 25);
      paramGraphics.setFont(new Font("Verdana", 0, 9));
      paramGraphics.setColor(Color.WHITE);
      try {
        if (j > 0) {
          long l2 = this.XPToLevelS / (j / 3600);
          l3 = l2 / 3600L;
          l2 -= l3 * 3600L;
          l4 = l2 / 60L;
          l2 -= l4 * 60L;
          paramGraphics.drawString("Next level in: " + l3 + ":" + l4 + ":" + l2, n + 8, i1 + 11);
        }
        else {
          paramGraphics.drawString("Next level in: 0:0:0", n + 8, i1 + 11);
        }
      } catch (Exception localException2) {
        paramGraphics.drawString("Next level in: -1:-1:-1", n + 8, i1 + 11);
      }
      paramGraphics.drawString("Casts to next level: " + (int)(this.XPToLevelS / this.BarEXP), n + 8, i1 + 22);
    }

    this.EXP1 = this.XPGainedMagic;
    if (this.EXP1 > this.EXP2) {
      this.EXP2 = this.EXP1;
      this.readyToCast = true;
    }
  }

  public boolean onStart()
  {
    this.Status = "Loading...";
    try {
      this.BKG = ImageIO.read(new URL("http://a.imageshack.us/img14/5392/superheater50paint.png"));
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    this.OPTION_FILE = new Properties();

    this.SuperheaterGUI = new FallenSuperheater.GUI(this, this);
    this.SuperheaterGUI.setLocationRelativeTo(null);
    this.SuperheaterGUI.setVisible(true);

    while (this.WaitForStart) {
      sleep(20);
    }

    if (!this.worked)
      return false;
    if (this.DoTheMath) {
      log("Obtaining G.E prices...");
      this.BarPrice = this.grandExchange.lookup(this.BarID).getGuidePrice();
      this.Ore1Price = this.grandExchange.lookup(this.Ore1).getGuidePrice();
      if (this.bankTwice) {
        this.Ore2Price = (this.grandExchange.lookup(this.Ore2).getGuidePrice() * this.Ore2PerSpell);
      }

      this.naturePrice = this.grandExchange.lookup(561).getGuidePrice();

      log("... prices retrieved!  ||  Profit/Bar: " + this.BarPrice + " - " + this.Ore1Price + " - " + this.Ore2Price + " - " + this.naturePrice + " = " + (this.BarPrice - this.Ore1Price - this.Ore2Price - this.naturePrice));
    }

    if (this.coalBag) {
      log("Magic XP/Cast: 53  ||  Smithing XP/" + this.BarType + " bar: " + this.BarEXP + "  ||  Using coal bag!");
    }
    else {
      log("Magic XP/Cast: 53  ||  Smithing XP/" + this.BarType + " bar: " + this.BarEXP + ".");
    }

    this.mouse.setSpeed(random(this.Mouse2 - 1, this.Mouse2 + 2));
    log(" ~ Anti-ban synchronized to " + Percentage + "% efficiency! || Mousespeed set to " + Mouse1 + "%! ~");

    if (this.TakeAShot)
      log("Will take a screenshot when finished, Fallen's Superheater is now running!");
    else {
      log("Fallen's Superheater is now running!");
    }
    if (AmountOfCasts != 0) {
      log("Logging out after " + AmountOfCasts + " casts!");
    }
    this.game.openTab(4);
    if (!this.inventory.contains(561)) {
      this.log.severe("Unable to find nature runes.");
      return false;
    }
    log("------------------------------------------------");
    this.startTime = System.currentTimeMillis();
    return true;
  }

  private FallenSuperheater.State getState()
  {
    if (!this.bank.isOpen()) {
      if ((this.DirectHeat) || (this.Continue))
        return FallenSuperheater.State.SUPERHEAT;
      if ((!this.Continue) && (this.BankTime))
        return FallenSuperheater.State.OPENBANK;
      if ((!this.DirectHeat) && (!this.Continue)) {
        int i = this.inventory.getCount(new int[] { this.Ore1 }); int j = this.inventory.getCount(new int[] { this.Ore2 });

        if ((i < 1) || (j < this.Ore2PerSpell) || (i > this.Ore1InvAm) || (j > this.Ore2InvAm))
        {
          return FallenSuperheater.State.OPENBANK;
        }
        return FallenSuperheater.State.SUPERHEAT;
      }

      return FallenSuperheater.State.SUPERHEAT;
    }

    return getBankState();
  }

  private FallenSuperheater.State getBankState()
  {
    if (!this.coalBag) {
      if (this.BarType == "Adamant") {
        return FallenSuperheater.State.AdamantBank;
      }
      return FallenSuperheater.State.DefaultBank;
    }

    return FallenSuperheater.State.CoalBagBank;
  }

  public int loop()
  {
    this.mouse.setSpeed(random(this.Mouse2 - 1, this.Mouse2 + 2));
    if (random(0, 75) == random(0, 75))
      this.mouse.moveRandomly(0, random(0, 75));
    if (failSafes())
      return 500;
    switch (FallenSuperheater.1.$SwitchMap$FallenSuperheater$State[getState().ordinal()]) {
    case 1:
      this.Status = "Superheating.";
      this.DirectHeat = false;
      if (!isSuperheatSelected()) {
        if (this.game.getCurrentTab() != 7) {
          this.game.openTab(7);
        }
        if (!this.bank.isOpen()) {
          try {
            if (this.magic.castSpell(50)) {
              waitForTab(4, 2500);
              if (this.game.getCurrentTab() != 4)
                spellCheck();
            }
            else {
              break;
            }
          } catch (Exception localException) {
          }
        } else {
          this.bank.close();
          break;
        }
      }
      if ((this.bank.isOpen()) || (this.game.getCurrentTab() != 4)) break;
      checkBooleans();
      RSItem localRSItem = getClosestItem(this.Ore1, this.mouse.getLocation());
      if (((localRSItem != null) && (localRSItem.doAction("Cast"))) || (atLastInventoryItem(this.Ore1, "Cast")))
      {
        spellAfterMath();
      }

      break;
    case 2:
      this.Status = "Opening the bank.";
      if (this.magic.isSpellSelected()) {
        this.game.openTab(4);
      }
      if (this.OpenedBank < 2) {
        if (new FallenSuperheater.FallenBank(this).open()) {
          this.OpenedBank = 0;
          this.BankTime = false;
        }
        else if (new FallenSuperheater.FallenBank(this).open()) {
          this.OpenedBank = 0;
          this.BankTime = false;
        } else {
          this.OpenedBank += 1;
        }

        this.mouse.moveRandomly(50);
      } else {
        this.game.openTab(random(0, 17));
        sleep(random(300, 600));
        this.game.openTab(4);
        this.OpenedBank = 0;
      }
      break;
    case 3:
      defaultBank();
      break;
    case 4:
      adamantBank();
      break;
    case 5:
      coalBagBank();
    }

    return random(10, 50);
  }

  private boolean failSafes()
  {
    if (this.bank.isOpen()) {
      if (this.inventory.containsOneOf(new int[] { 14664, 11640, 2528, 6199 }))
      {
        this.bank.close();
        sleep(random(1000, 1200));
        log("Rewards-Box failsafed.");
        this.game.openTab(4);
        sleep(random(500, 1000));
        return true;
      }
    }
    if (!gainedExperience()) {
      Quit();
      return true;
    }
    try {
      if (getMyPlayer().getAnimation() == 9633) {
        log("What the heck, we're alching... Better quit now.");
        Quit();
        return true;
      }
    } catch (Exception localException) {
      localException.printStackTrace();
    }
    return false;
  }

  private boolean isSuperheatSelected() {
    return (this.magic.isSpellSelected()) && (this.game.getCurrentTab() == 4);
  }

  private void spellCheck()
  {
    String[] arrayOfString1 = this.menu.getActions();
    int i = 0;
    for (String str : arrayOfString1) {
      if (str.equals("Cast Superheat Item")) {
        i = 1;
      }
    }
    if (i == 0) {
      if (this.browser > 4) {
        if (this.magic.getInterface().getComponent(13).doClick())
        {
          log("Show skill-spells enabled.");
          this.browser = 0;
          sleep(random(1500, 2000));
        }
        return;
      }
      this.browser += 1;
    }
    else {
      this.browser = 0;
    }
  }

  private boolean spellAfterMath()
  {
    if (random(0, 3) == random(0, 3)) {
      this.mouse.moveRandomly(3);
    }

    AntiBan();
    waitForMageTabWO(2500, true);
    if ((AmountOfCasts != 0) && 
      (this.BarCounter >= AmountOfCasts)) {
      Quit();
      log("Goal achieved!");
      return false;
    }

    return true;
  }

  private RSItem getClosestItem(int paramInt, Point paramPoint)
  {
    for (int i = 1; i < 800; i += 2) {
      this.R = i;
      this.P = paramPoint;
      this.DRAW = true;
      this.Circle = new Ellipse2D.Double(paramPoint.getX() - i / 2, paramPoint.getY() - i / 2, i, i);

      RSComponent[] arrayOfRSComponent1 = this.inventory.getInterface().getComponents();
      for (RSComponent localRSComponent : arrayOfRSComponent1) {
        if (this.Circle.contains(localRSComponent.getCenter())) {
          RSItem localRSItem = this.inventory.getItemAt(localRSComponent.getComponentIndex());
          if ((localRSItem == null) || 
            (localRSItem.getID() != paramInt)) continue;
          this.Rect = localRSComponent.getArea();
          return localRSItem;
        }

      }

    }

    return null;
  }

  private boolean gainedExperience() {
    if (!this.expTimeOut.isRunning()) {
      this.XPGained = (this.XPGainedSmithing + this.XPGainedMagic);
      if (this.XPGained > this.tempExp) {
        this.expTimeOut = new Timer(300000L);
        this.tempExp = this.XPGained;
        return true;
      }
      log("No experience gained withtin the past 5 minutes!");
      return false;
    }

    return true;
  }

  private void checkBooleans()
  {
    if (this.game.getCurrentTab() != 4) {
      this.game.openTab(4);
    }
    int i = this.inventory.getCount(new int[] { this.Ore1 }); int j = this.inventory.getCount(new int[] { this.Ore2 });

    if (i < 1) {
      i = this.inventory.getCount(new int[] { this.Ore1 });
    }
    if (j < 1) {
      j = this.inventory.getCount(new int[] { this.Ore2 });
    }
    this.filled = false;
    if (!this.coalBag) {
      if (this.BarType != "Adamant") {
        if (((i > 1) && (!this.bankTwice)) || ((this.bankTwice) && (i > 1) && (j > this.Ore2PerSpell)))
        {
          this.Continue = true;
          this.BankTime = false;
        } else {
          this.Continue = false;
          this.BankTime = true;
        }
      }
      else if ((i > 1) && (j > this.Ore2PerSpell)) {
        this.Continue = true;
        this.BankTime = false;
      } else {
        this.Continue = false;
        this.BankTime = true;
      }

    }
    else if ((i > 1) && (j > this.Ore2PerSpell)) {
      this.Continue = true;
      this.BankTime = false;
    } else {
      this.Continue = false;
      this.BankTime = true;
    }
  }

  private void coalBagBank()
  {
    this.Status = "Banking.";
    if (!this.bank.isOpen()) {
      return;
    }
    if (!this.inventory.contains(18339)) {
      if (WD(18339, 1)) {
        waitForWithdrawnItem(18339, random(2000, 3000));
      }
      return;
    }
    this.OpenedBank = 0;
    int i = this.inventory.getCount(new int[] { this.Ore1 }); int j = this.inventory.getCount(new int[] { this.Ore2 });

    if (this.inventory.getCountExcept(new int[] { 561, 18339, this.Ore1, this.Ore2 }) > 0) {
      try {
        depositAllExcept(new int[] { 561, 18339, this.Ore1, this.Ore2 });
      } catch (Exception localException1) {
      }
      return;
    }
    if (!this.filled) {
      if (j < 26) {
        if (this.inventory.getCountExcept(new int[] { 18339, 561, this.Ore2 }) > 0) {
          try {
            depositAllExcept(new int[] { 561, 18339, this.Ore2 });
          } catch (Exception localException2) {
          }
          return;
        }
        if (WD(this.Ore2, this.Ore2WD)) {
          waitForWithdrawnItem(this.Ore2, random(2000, 3000));
        }
        return;
      }

      RSItem localRSItem = this.inventory.getItem(new int[] { 18339 });
      if ((localRSItem != null) && 
        (localRSItem.doAction("Fill Coal bag"))) {
        waitForDepositedItem(random(2000, 3000));
        sleep(random(100, 200));
      }

      return;
    }

    if (i == 0) {
      if (this.inventory.getCount() > 28 - this.Ore1InvAm) {
        try {
          depositAllExcept(new int[] { 561, 18339 });
        } catch (Exception localException3) {
        }
        return;
      }
      if (WD(this.Ore1, this.Ore1WD)) {
        waitForWithdrawnItem(this.Ore1, random(2000, 3000));
      }
      return;
    }if ((i > 0) && (i != this.Ore1InvAm)) {
      this.bank.deposit(this.Ore1, 0);
      waitForDepositedItem(random(2000, 3000));
      return;
    }
    if (!this.inventory.isFull()) {
      if (WD(this.Ore2, this.Ore2WD)) {
        waitForWithdrawnItem(this.Ore2, random(2000, 3000));
      }
      return;
    }
    if (this.game.getCurrentTab() == 7) {
      this.DirectHeat = true;
    }
    this.BankTime = false;
    this.bank.close();
  }

  private void adamantBank()
  {
    this.Status = "Banking.";
    if (!this.bank.isOpen()) {
      return;
    }
    this.OpenedBank = 0;
    int i = this.inventory.getCount(new int[] { this.Ore1 }); int j = this.inventory.getCount(new int[] { this.Ore2 });
    int k = this.inventory.getCount(new int[] { this.BarID });
    if (this.inventory.getCountExcept(new int[] { this.Ore1, this.Ore2, 561, this.BarID }) > 0) {
      try {
        depositAllExcept(new int[] { this.Ore1, this.Ore2, 561, this.BarID });
      } catch (Exception localException1) {
      }
      return;
    }
    if (k >= 9) {
      try {
        depositAllExcept(new int[] { 561 });
      } catch (Exception localException2) {
      }
      return;
    }if (k == 0) {
      if (i == 0) {
        if (WD(this.Ore1, this.Ore1WD)) {
          waitForWithdrawnItem(this.Ore1, random(2000, 3000));
        }
        return;
      }if (i == 9) {
        if (j == 18) {
          if (this.game.getCurrentTab() == 7) {
            this.DirectHeat = true;
          }
          this.BankTime = false;
          this.bank.close();
          return;
        }
        if (WD(this.Ore2, this.Ore2WD)) {
          waitForWithdrawnItem(this.Ore2, random(2000, 3000));
        }
        return;
      }

      this.bank.deposit(this.Ore1, 0);
      waitForDepositedItem(random(2000, 2500));
      return;
    }
    if ((k > 0) && (k < 9)) {
      if (this.inventory.getCountExcept(new int[] { 561, this.Ore1, this.Ore2, this.BarID }) > 0) {
        try {
          depositAllExcept(new int[] { 561, this.Ore1, this.Ore2, this.BarID });
        } catch (Exception localException3) {
        }
        return;
      }
      if (j < 18) {
        if (WD(this.Ore2, this.Ore2WD)) {
          waitForWithdrawnItem(this.Ore2, random(2000, 3000));
        }
        return;
      }
      if (this.game.getCurrentTab() == 7) {
        this.DirectHeat = true;
      }
      this.BankTime = false;
      this.bank.close();
      return;
    }
    try
    {
      depositAllExcept(new int[] { 561 });
    }
    catch (Exception localException4)
    {
    }
  }

  private void defaultBank() {
    this.Status = "Banking.";
    if (!this.bank.isOpen()) {
      return;
    }
    this.OpenedBank = 0;
    int i = this.inventory.getCount(new int[] { this.Ore1 });
    int j = this.inventory.getCount(new int[] { this.Ore2 });
    if (this.inventory.getCountExcept(new int[] { 561, this.Ore1, this.Ore2 }) > 0) {
      try {
        depositAllExcept(new int[] { 561, this.Ore1, this.Ore2 });
      } catch (Exception localException1) {
      }
      return;
    }
    if (this.bankTwice) {
      if (i == 0) {
        if (WD(this.Ore1, this.Ore1WD)) {
          waitForWithdrawnItem(this.Ore1, random(2000, 3000));
        }
        return;
      }if ((i > 0) && (i < this.Ore1InvAm)) {
        try {
          if (j != this.Ore2InvAm) {
            this.bank.deposit(this.Ore1, 0);
            waitForDepositedItem(random(2000, 3000));
          }
          else if (WD(this.Ore1, this.Ore1WD)) {
            waitForWithdrawnItem(this.Ore1, random(2000, 3000));
          }
        }
        catch (Exception localException2)
        {
        }
        return;
      }if (i > this.Ore1InvAm) {
        try {
          this.bank.deposit(this.Ore1, 0);
          waitForDepositedItem(random(2000, 3000));
        } catch (Exception localException3) {
        }
        return;
      }
      if (j == 0) {
        if (WD(this.Ore2, this.Ore2WD)) {
          waitForWithdrawnItem(this.Ore2, random(2000, 3000));
        }
        return;
      }if ((j > 0) && (j < this.Ore2InvAm)) {
        try {
          if (i != this.Ore1InvAm) {
            this.bank.deposit(this.Ore2, 0);
            waitForDepositedItem(random(2000, 3000));
          }
          else if (WD(this.Ore2, this.Ore2WD)) {
            waitForWithdrawnItem(this.Ore2, random(2000, 3000));
          }
        }
        catch (Exception localException4)
        {
        }
        return;
      }if (j > this.Ore2InvAm) {
        try {
          this.bank.deposit(this.Ore2, 0);
          waitForDepositedItem(random(2000, 3000));
        } catch (Exception localException5) {
        }
        return;
      }
      if (this.game.getCurrentTab() == 7) {
        this.DirectHeat = true;
      }
      this.BankTime = false;
      this.bank.close();
      return;
    }

    if (i == 0) {
      if (WD(this.Ore1, this.Ore1WD)) {
        waitForWithdrawnItem(this.Ore1, random(2000, 3000));
      }
      return;
    }if ((i > 0) && (i < this.Ore1InvAm)) {
      if (WD(this.Ore1, this.Ore1WD)) {
        waitForWithdrawnItem(this.Ore1, random(2000, 3000));
      }
      return;
    }if (i > this.Ore1InvAm) {
      try {
        this.bank.deposit(this.Ore1, 0);
        waitForDepositedItem(random(2000, 3000));
      } catch (Exception localException6) {
      }
      return;
    }
    if (this.game.getCurrentTab() == 7) {
      this.DirectHeat = true;
    }
    this.BankTime = false;
    this.bank.close();
  }

  public boolean waitForIF(RSInterface paramRSInterface, int paramInt)
  {
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt) {
      if (paramRSInterface.isValid()) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  public boolean waitForMageTabWO(int paramInt, boolean paramBoolean) {
    long l = System.currentTimeMillis();
    int i = random(600, 900);
    if (random(0, 33) == random(0, 33))
      this.mouse.moveRandomly(33);
    while (System.currentTimeMillis() - l < paramInt) {
      if ((this.BankTime) && (System.currentTimeMillis() - l > i)) {
        return true;
      }
      if (!paramBoolean) {
        if (this.game.getCurrentTab() == 7) {
          return true;
        }
      }
      else if ((this.game.getCurrentTab() == 7) && (this.readyToCast)) {
        this.readyToCast = false;
        sleep(random(0, random(0, 200)));
        return true;
      }

      sleep(25);
    }
    return false;
  }

  public boolean waitForTab(int paramInt1, int paramInt2) {
    long l = System.currentTimeMillis();
    while (System.currentTimeMillis() - l < paramInt2) {
      if (this.game.getCurrentTab() == paramInt1) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  private boolean atLastInventoryItem(int paramInt, String paramString) {
    try {
      if ((this.game.getCurrentTab() != 4) && (!this.interfaces.get(762).isValid()))
      {
        this.game.openTab(4);
      }
      RSComponent localRSComponent = this.inventory.getInterface();
      if ((localRSComponent == null) || (localRSComponent.getComponents() == null)) {
        return false;
      }
      ArrayList localArrayList = new ArrayList();
      for (Object localObject2 : localRSComponent.getComponents()) {
        if ((localObject2 != null) && (localObject2.getComponentID() == paramInt)) {
          localArrayList.add(localObject2);
        }
      }
      if (localArrayList.size() == 0)
        return false;
      ??? = (RSComponent)localArrayList.get(localArrayList.size());
      return ((RSComponent)???).doAction(paramString);
    } catch (Exception localException) {
      log("atInventoryItem(int itemID, String option) Error: " + localException);
    }return false;
  }

  public boolean depositAllExcept(int[] paramArrayOfInt)
  {
    if ((this.bank.isOpen()) || (this.bank.isDepositOpen())) {
      int i = 1;
      int j = this.bank.isOpen() ? this.inventory.getCount(true) : this.bank.getBoxCount();

      for (int k = 0; k < 28; k++) {
        RSComponent localRSComponent = this.bank.isOpen() ? this.inventory.getItemAt(k).getComponent() : this.interfaces.get(11).getComponent(17).getComponent(k);

        if ((localRSComponent != null) && (localRSComponent.getComponentID() != -1)) {
          int[] arrayOfInt = paramArrayOfInt; int n = arrayOfInt.length; int i1 = 0;
          while (true) if (i1 < n) { int i2 = arrayOfInt[i1];
              if (localRSComponent.getComponentID() == i2)
                break;
              i1++; continue;
            }
            else
            {
              int m = 0;
              while (true) if (m < 5) {
                  if (localRSComponent.doAction(this.inventory.getCount(true, new int[] { localRSComponent.getComponentID() }) > 1 ? "Deposit-All" : "Deposit"))
                  {
                    waitForDepositedItem(random(2000, 3000));
                    n = this.bank.isOpen() ? this.inventory.getCount(true) : this.bank.getBoxCount();

                    if (n < j) {
                      j = n;
                      break;
                    }
                  }
                  m++; continue;
                }
                else
                {
                  i = 0;
                } 
            } 
        }
      }
      return i;
    }
    return false;
  }

  private boolean WD(int paramInt1, int paramInt2) {
    int i = paramInt2;
    if (paramInt2 == 0)
      i = this.Ore2PerSpell;
    if (paramInt2 < 0)
      throw new IllegalArgumentException("count < 0 (" + paramInt2 + ")");
    if (!this.bank.isOpen())
      return false;
    RSItem localRSItem = this.bank.getItem(paramInt1);
    if ((localRSItem != null) && (localRSItem.isComponentValid())) { if (this.bank.getCount(new int[] { paramInt1 }) >= i); } else {
      log("Out of items - Check: 1/3.");
      sleep(random(400, 600));
      if (this.bank.getCount(new int[] { paramInt1 }) < i) {
        log("Out of items - Check: 2/3.");
        sleep(random(400, 600));
        if ((this.bank.getCount(new int[] { paramInt1 }) < i) && (this.bank.isOpen())) {
          try {
            log("Out of: " + this.grandExchange.getItemName(paramInt1) + " - Check 3/3.");
          }
          catch (Exception localException) {
            localException.printStackTrace();
            log("Out of: " + paramInt1);
          }
          Quit();
          return false;
        }
      }
    }
    switch (paramInt2) {
    case 0:
      return localRSItem.doAction("Withdraw-All");
    case 1:
      return localRSItem.doClick(true);
    case 5:
    case 10:
      return localRSItem.doAction("Withdraw-" + paramInt2);
    }
    if (localRSItem.doClick(false)) {
      sleep(random(100, 300));
      if (this.menu.contains("Withdraw-" + paramInt2 + " ")) {
        if (this.menu.doAction("Withdraw-" + paramInt2 + " ")) {
          sleep(random(100, 200));
          return true;
        }
        return false;
      }
      if (localRSItem.doAction("Withdraw-X")) {
        sleep(random(1000, 1300));
        this.keyboard.sendText("" + paramInt2, true);
      }
      sleep(random(100, 200));
      return true;
    }

    return false;
  }

  private boolean waitForWithdrawnItem(int paramInt1, int paramInt2) {
    int i = this.inventory.getCount(true, new int[] { paramInt1 });
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt2) {
      if (this.inventory.getCount(new int[] { paramInt1 }) > i) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  private boolean waitForDepositedItem(int paramInt) {
    int i = this.inventory.getCount(true);
    long l = System.currentTimeMillis();

    while (System.currentTimeMillis() - l < paramInt) {
      if (this.inventory.getCount(true) < i) {
        return true;
      }
      sleep(100);
    }
    return false;
  }

  public void Quit()
  {
    this.Status = "Quitting.";
    if (this.TakeAShot) {
      this.env.saveScreenshot(true);
      sleep(500);
    }
    stopScript();
  }

  boolean hoverPlayer()
  {
    Object localObject = null;
    RSPlayer[] arrayOfRSPlayer = this.players.getAll();

    localObject = arrayOfRSPlayer[random(0, arrayOfRSPlayer.length - 1)];
    if (localObject != null) { String str2;
      try { String str1 = localObject.getName();
        str2 = getMyPlayer().getName();
        if (str1.equals(str2))
          return false;
      } catch (NullPointerException localNullPointerException)
      {
      }
      try {
        RSTile localRSTile = localObject.getLocation();
        str2 = localObject.getName();
        Point localPoint = this.calc.tileToScreen(localRSTile);
        if ((this.calc.pointOnScreen(localPoint)) && (localPoint != null)) {
          this.mouse.click(localPoint, 5, 5, false);
          log("ANTIBAN - Hover Player - Right click on " + str2);
        } else {
          return false;
        }
        return true;
      }
      catch (Exception localException) {
      } }
    return false;
  }

  public void hoverObject() {
    examineRandomObject(5);
    sleep(randGenerator(50, 1000));
    int i = randGenerator(0, 4);
    sleep(randGenerator(100, 800));
    if ((i == 1) && (i == 2))
      this.mouse.move(1, 1, 760, 500);
  }

  int randGenerator(int paramInt1, int paramInt2)
  {
    return paramInt1 + (int)(Math.random() * (paramInt2 - paramInt1));
  }

  public RSTile examineRandomObject(int paramInt) {
    RSTile localRSTile1 = getMyPlayer().getLocation();
    ArrayList localArrayList = new ArrayList();
    for (int i = 1; i < paramInt * paramInt; i += 2) {
      for (int j = 0; j < i; j++) {
        for (int k = 0; k < i; k++) {
          int m = (i + 1) / 2 - 1;
          if ((j > 0) && (j < i - 1)) {
            k = i - 1;
          }
          RSTile localRSTile3 = new RSTile(localRSTile1.getX() - m + j, localRSTile1.getY() - m + k);

          RSObject localRSObject = this.objects.getTopAt(localRSTile3);
          if ((localRSObject == null) || (!this.calc.tileOnScreen(localRSObject.getLocation())))
            continue;
          localArrayList.add(localRSObject.getLocation());
        }
      }
    }

    if (localArrayList.size() == 0) {
      return null;
    }
    if ((localArrayList.size() > 0) && (localArrayList != null)) {
      RSTile localRSTile2 = (RSTile)localArrayList.get(randGenerator(0, localArrayList.size()));

      Point localPoint = this.calc.tileToScreen(localRSTile2);
      if (localPoint != null)
        try {
          this.mouse.move(localPoint);
          if (this.menu.doAction("Examine"));
          sleep(random(100, 500));
        }
        catch (NullPointerException localNullPointerException) {
        }
    }
    return null;
  }

  public void AntiBan()
  {
    try
    {
      int i = random(1, 15000 / Percentage);
      int j = random(1, 10000 / Percentage);
      int k = random(1, 13000 / Percentage);
      int m = random(1, 10000 / Percentage);
      int n = random(1, 2000 / Percentage);
      int i1 = random(1, 8000 / Percentage);

      if (Percentage != 0)
        if (i == 5) {
          waitForMageTabWO(1500, false);
          this.Status = "ANTIBAN - Checking Stats.";
          this.game.openTab(2);
          sleep(random(150, 250));
          if (this.game.getCurrentTab() != 2) {
            return;
          }
          sleep(random(400, 800));
          this.mouse.move(554, 213, 175, 215);
          sleep(random(400, 800));
          this.mouse.move(554, 213, 175, 215);
          sleep(random(400, 1000));
          this.mouse.moveRandomly(700);
          sleep(random(300, 500));
          this.game.openTab(7);
        } else if (j == 5) {
          this.Status = "ANTIBAN - Clicking a player.";
          hoverPlayer();
          sleep(random(1150, 2800));
          this.mouse.moveRandomly(750);
          sleep(random(400, 1000));
        } else if (i1 == 5) {
          this.Status = "ANTIBAN - Clicking an object.";
          hoverObject();
          sleep(random(1150, 2800));
          this.mouse.moveRandomly(750);
          sleep(random(400, 1000));
        }
        else
        {
          int i2;
          if (k == 5) {
            waitForMageTabWO(1500, false);
            this.Status = "ANTIBAN - XP Check.";
            i2 = random(0, 100);
            if (i2 > 50) {
              this.game.openTab(2);
              sleep(random(150, 250));
              if (this.game.getCurrentTab() != 2) {
                return;
              }
              sleep(random(400, 800));
              this.mouse.move(584, 364, 20, 10);
              sleep(random(800, 1200));
              this.mouse.move(584, 364, 20, 10);
              sleep(random(900, 1750));
              this.mouse.moveRandomly(700);
              sleep(random(300, 800));
              this.game.openTab(7);
            } else if (i2 < 51) {
              this.game.openTab(2);
              sleep(random(150, 250));
              if (this.game.getCurrentTab() != 2) {
                return;
              }
              sleep(random(400, 800));
              this.mouse.move(707, 252, 20, 10);
              sleep(random(800, 1200));
              this.mouse.move(707, 252, 20, 10);
              sleep(random(900, 1750));
              this.mouse.moveRandomly(700);
              sleep(random(300, 800));
              this.game.openTab(7);
            }
          } else if (m == 5) {
            switch (random(1, 4)) {
            case 1:
              this.Status = "ANTIBAN - AFK'ing.";
              sleep(random(AFK1, AFK2));
              break;
            case 2:
              this.Status = "ANTIBAN - AFK'ing.";
              sleep(random(AFK1 / 4, AFK2 / 10));
              this.mouse.moveRandomly(750);
              sleep(random(AFK1, AFK2));
              break;
            case 3:
              this.Status = "ANTIBAN - AFK'ing.";
              sleep(random(0, 500));
              this.mouse.moveRandomly(1000);
              sleep(random(AFK1 / 4, AFK2 / 10));
              this.mouse.moveRandomly(1500);
              sleep(random(AFK1, AFK2));
            }
          }
          else if (n == 5) {
            i2 = random(1, 6);
            switch (i2) {
            case 1:
              new FallenSuperheater.CameraRotateThread(this).start();
              break;
            case 2:
              new FallenSuperheater.CameraHeightThread(this).start();
              break;
            case 3:
              new FallenSuperheater.CameraRotateThread(this).start();
              if (random(0, 100) <= random(0, 50)) break;
              sleep(random(100, 2000));
              new FallenSuperheater.CameraRotateThread(this).start(); break;
            case 4:
              new FallenSuperheater.CameraHeightThread(this).start();
              if (random(0, 100) <= random(0, 50)) break;
              sleep(random(100, 2000));
              new FallenSuperheater.CameraHeightThread(this).start(); break;
            case 5:
              new FallenSuperheater.CameraRotateThread(this).start();
              new FallenSuperheater.CameraHeightThread(this).start();
              if (random(0, 100) > random(0, 50)) {
                sleep(random(100, 2000));
                new FallenSuperheater.CameraRotateThread(this).start();
              }
              if (random(0, 100) <= random(0, 50)) break;
              sleep(random(100, 1000));
              new FallenSuperheater.CameraHeightThread(this).start();
            }
          }
        }
    }
    catch (Exception localException)
    {
      localException.initCause(localException);
    }
  }

  public void bankingAntiBan()
  {
    if (random(0, 400 / Percentage) == 2) {
      int i = random(1, 4);
      switch (i) {
      case 1:
        new FallenSuperheater.CameraRotateThread(this).start();
        break;
      case 2:
        new FallenSuperheater.CameraHeightThread(this).start();
        break;
      case 3:
        int j = random(0, 2);
        if (j == 0) {
          new FallenSuperheater.CameraRotateThread(this).start();
          new FallenSuperheater.CameraHeightThread(this).start();
        } else {
          new FallenSuperheater.CameraHeightThread(this).start();
          new FallenSuperheater.CameraRotateThread(this).start();
        }
      }
    }
  }

  public void messageReceived(MessageEvent paramMessageEvent)
  {
    String str = paramMessageEvent.getMessage().toLowerCase();
    if (str.contains("have enough nat")) {
      log("Out of nature runes!");
      Quit();
    }
    if (str.contains("have enough fir")) {
      log("Out of fire runes!");
      log("Please equip a staff with unlimited fire runes.");
      Quit();
    }
    if (str.contains("coal bag is already")) {
      this.filled = true;
    }
    if (str.contains("add the coal to your"))
      this.filled = true;
  }

  public void onFinish()
  {
    log(this.BarCounter + " " + this.BarType + " bars made in: " + this.hours + ":" + this.minutes + ":" + this.seconds + ".");

    log("Thank you for using Fallen's Superheater.");
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
    Point localPoint = new Point(paramMouseEvent.getPoint());
    Rectangle localRectangle = new Rectangle(497, 458, 15, 14);
    if ((localRectangle.contains(localPoint)) && (this.renew))
      if (this.Option == 1) {
        this.Option = 2;
        this.renew = false;
      } else if (this.Option == 2) {
        this.Option = 3;
        this.renew = false;
      } else if (this.Option == 3) {
        this.Option = 1;
        this.renew = false;
      }
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
    this.renew = true;
  }

  public void mouseDragged(MouseEvent paramMouseEvent)
  {
  }

  public void mouseMoved(MouseEvent paramMouseEvent)
  {
    Point localPoint = new Point(paramMouseEvent.getPoint());
    Rectangle localRectangle1 = new Rectangle(262, 358, 170, 17);
    Rectangle localRectangle2 = new Rectangle(271, 215, 170, 17);
    Rectangle localRectangle3 = new Rectangle(53, 358, 170, 17);
    Rectangle localRectangle4 = new Rectangle(62, 215, 170, 17);

    if (this.Option == 1) {
      if (localRectangle1.contains(localPoint)) {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.STTNL = true;
      } else {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.STTNL = false;
      }
      if (localRectangle3.contains(localPoint)) {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.MTTNL = true;
      } else {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.MTTNL = false;
      }
    }
    if (this.Option == 2) {
      if (localRectangle2.contains(localPoint)) {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.STTNL = true;
      } else {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.STTNL = false;
      }
      if (localRectangle4.contains(localPoint)) {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.MTTNL = true;
      } else {
        this.mouseSpot = new Point(paramMouseEvent.getPoint());
        this.MTTNL = false;
      }
    }
  }
}